package businessObjects;

import java.sql.SQLException;
import java.util.ArrayList;

import model.Cours;
import model.Seance;

import connection.ConnectionDAO;
import connection.JDCConnection;
import dao.SessionCouranteDAO;

public class SessionCouranteBo {
	private SessionCouranteDAO dao;
	private ConnectionDAO con;
	
	public SessionCouranteBo() {
		dao = new SessionCouranteDAO();
		con = new ConnectionDAO();
	}
	
	public ArrayList<Cours> getCoursSessionCourante(int idEtudiant) throws SQLException {
		JDCConnection c = con.getConnection();
		ArrayList<Cours> list = dao.getCoursSessionCourante(c, idEtudiant);
		c.close();
		return list;
	}
	
	
	public int getNbCreditInscrit (int idEtudiant) throws SQLException {
		JDCConnection c = con.getConnection();
		int nbrCredit = dao.getNbCreditInscrit(c, idEtudiant);
		c.close();
		return nbrCredit;
	}
	
	
	public boolean addGroupe(int idGroupe, int idEtudiant) throws SQLException {
		JDCConnection c = con.getConnection();
		boolean valid = dao.addGroupe(c, idGroupe, idEtudiant);
		if(valid) {
			c.commit();
		}
		else {
			c.rollback();
		}
		c.close();
		return valid;
	}
	
	public boolean removeGroupe(int idGroupe, int idEtudiant) throws SQLException {
		JDCConnection c = con.getConnection();
		boolean valid = dao.removeGroupe(c, idGroupe, idEtudiant);
		if(valid) {
			c.commit();
		}
		else {
			c.rollback();
		}
		c.close();
		return valid;
	}
	
	public ArrayList<Seance> getSeanceListByEtudiantId(int idEtudiant) throws SQLException {
		JDCConnection c = con.getConnection();
		ArrayList<Seance> list = dao.getSeanceListByEtudiantId(c, idEtudiant);
		c.close();
		return list;
	}
}
